﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using GameService;

namespace Website
{
    public partial class signup : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Create_Click(object sender, EventArgs e)
        {
            if (txtPassword.Text != txtPassword2.Text)
            {
                lblMessage.Text = "Passwords don't match";
                lblMessage.Visible = true;
                return;
            }

            bool success = false;

            AddingNewUserResult addRes = Master.GameManager.AddUser(txtUserName.Text, txtPassword.Text, txtEmail.Text);
            if (addRes == AddingNewUserResult.UserExist)
                lblMessage.Text = ("User already exists");
            else if (addRes == AddingNewUserResult.IncorrectEmail)
                lblMessage.Text = ("Email is invalid");
            else if (addRes == AddingNewUserResult.UnknownError)
                lblMessage.Text = ("Adding user failed due to unknown reason");
            else
                success = true;

            if (success)
            {
                Master.SetUser(txtUserName.Text);
                Response.Redirect("gamelist.aspx");
            }
            else
            {
                lblMessage.Visible = true;
            }
        }
    }
}
